//
//  LCTabBarController.swift
//  LazyCooking-Swift
//
//  Created by 赵隆杰 on 2024/10/7.
//

import UIKit

class LCTabBarController: UITabBarController {
    
    private final let tabbarData = [
        [
            "vc": LCHomeViewController.init(),
            "title": "首页",
            "imageStr": "",
            "selectedImageStr": ""
        ],
        [
            "vc": LCCookbookViewController.init(),
            "title": "菜谱",
            "imageStr": "",
            "selectedImageStr": ""
        ],
        [
            "vc": LCSquareViewController.init(),
            "title": "广场",
            "imageStr": "",
            "selectedImageStr": ""
        ],
        [
            "vc": LCMineViewController.init(),
            "title": "我的",
            "imageStr": "",
            "selectedImageStr": ""
        ]
    ]

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        
        // Do any additional setup after loading the view.
        var temp_array: [LCNavigationController] = []
        for dict in tabbarData {
            if let nav = addNavWithDict(dict) {
                temp_array.append(nav)
            }
        }
        self.viewControllers = temp_array
        tabBar.backgroundColor = .white
        tabBar.tintColor = .purple
        tabBar.isTranslucent = false
    }
    
    func addNavWithDict(_ dict: Dictionary<String, Any>) -> LCNavigationController? {

        let nav = LCNavigationController.init(rootViewController: (dict["vc"] as! UIViewController))
        nav.tabBarItem!.title = (dict["title"] as! String)
        let image = UIImage.init(named: (dict["imageStr"] as! String))
        image?.withRenderingMode(.alwaysOriginal)
        let selectedImage = UIImage.init(named: (dict["selectedImageStr"] as! String))
        selectedImage?.withRenderingMode(.alwaysOriginal)
        nav.tabBarItem.image = image
        nav.tabBarItem.selectedImage = selectedImage
        return nav
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
